package com.meiqiongproperty.yiguanjia.utils.image;

import android.content.Context;
import android.graphics.Bitmap;

import com.ctrip.android.asyncimageloader.cache.disc.naming.Md5FileNameGenerator;
import com.ctrip.android.asyncimageloader.cache.memory.impl.LRULimitedMemoryCache;
import com.ctrip.android.asyncimageloader.core.DisplayImageOptions;
import com.ctrip.android.asyncimageloader.core.ImageLoader;
import com.ctrip.android.asyncimageloader.core.ImageLoaderConfiguration;
import com.ctrip.android.asyncimageloader.utils.L;
import com.meiqiongproperty.yiguanjia.R;

/**
 * @author Chen
 * @version V1.0
 * @package com.sameway.cnotes.utils.image
 * @date 17/2/6
 */
public class CApplicationInitUtil {
    @SuppressWarnings("deprecation")
    public static void initImageLoader(Context context) {
        int memoryCacheSize = (int) (Runtime.getRuntime().maxMemory() / 8);

        LRULimitedMemoryCache memoryCache;
        memoryCache = new LRULimitedMemoryCache(memoryCacheSize);
        L.enableLogging();
        // 默认options用于加载小图, 大图页面请自行配置相关占位图片
        DisplayImageOptions options = new DisplayImageOptions.Builder()
                .showStubImage(R.mipmap.ic_launcher)
                .showImageForEmptyUri(R.mipmap.ic_launcher)
                .showImageOnFail(R.mipmap.ic_launcher).cacheInMemory(true)
                .cacheOnDisc(true).bitmapConfig(Bitmap.Config.RGB_565).build();
        ImageLoaderConfiguration.Builder builder = new ImageLoaderConfiguration.Builder(
                context).threadPriority(Thread.NORM_PRIORITY - 2)
                .memoryCache(memoryCache).discCacheDir("/Qed/cache")
                .defaultDisplayImageOptions(options)
                .discCacheFileNameGenerator(new Md5FileNameGenerator())
                .denyCacheImageMultipleSizesInMemory();

        ImageLoader.getInstance().init(builder.build());
    }
}
